home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / math / ast53src.zip / PLACALC.H < prev    next >
C/C++ Source or Header  |  1996-09-29  |  16KB  |  447 lines

  1. /*
  2. ** Astrolog (Version 5.30) File: placalc.h
  3. **
  4. ** IMPORTANT NOTICE: The graphics database and chart display routines
  5. ** used in this program are Copyright (C) 1991-1996 by Walter D. Pullen
  6. ** (Astara@msn.com, http://www.magitech.com/~cruiser1/astrolog.htm).
  7. ** Permission is granted to freely use and distribute these routines
  8. ** provided one doesn't sell, restrict, or profit from them in any way.
  9. ** Modification is allowed provided these notices remain with any
  10. ** altered or edited versions of the program.
  11. **
  12. ** The main planetary calculation routines used in this program have
  13. ** been Copyrighted and the core of this program is basically a
  14. ** conversion to C of the routines created by James Neely as listed in
  15. ** Michael Erlewine's 'Manual of Computer Programming for Astrologers',
  16. ** available from Matrix Software. The copyright gives us permission to
  17. ** use the routines for personal use but not to sell them or profit from
  18. ** them in any way.
  19. **
  20. ** The PostScript code within the core graphics routines are programmed
  21. ** and Copyright (C) 1992-1993 by Brian D. Willoughby
  22. ** (brianw@sounds.wa.com). Conditions are identical to those above.
  23. **
  24. ** The extended accurate ephemeris databases and formulas are from the
  25. ** calculation routines in the program "Placalc" and are programmed and
  26. ** Copyright (C) 1989,1991,1993 by Astrodienst AG and Alois Treindl
  27. ** (alois@azur.ch). The use of that source code is subject to
  28. ** regulations made by Astrodienst Zurich, and the code is not in the
  29. ** public domain. This copyright notice must not be changed or removed
  30. ** by any user of this program.
  31. **
  32. ** Initial programming 8/28,30, 9/10,13,16,20,23, 10/3,6,7, 11/7,10,21/1991.
  33. ** X Window graphics initially programmed 10/23-29/1991.
  34. ** PostScript graphics initially programmed 11/29-30/1992.
  35. ** Last code change made 9/22/1996.
  36. */
  37.  
  38. #include "astrolog.h"
  39. /* "planet" is defined to be cp0.obj, but is often a local in Placalc code. */
  40. #undef planet
  41.  
  42.  
  43. #define EPHE_PATH EPHE_DIR
  44. #define HUGE8 1.7E+308     /* biggest value for REAL8 */
  45.  
  46. extern int lrz_file_posit();
  47. extern int ast_file_posit();
  48. extern int chi_file_posit();
  49. extern int outer_hel();
  50. extern void longreorder();
  51. extern int inpolq();
  52.  
  53. #ifdef PLACALC
  54. /************************************************************
  55. $Header: placalc.h,v 1.4 93/03/22 10:08:39 alois Exp $
  56. definitions and constants for planetary routines
  57.  
  58. ATTENTION: PLACALC USERS ON MSDOS:
  59. See the note close to the end of this file regarding EPHE_PATH.
  60.  
  61. ---------------------------------------------------------------
  62. | Copyright Astrodienst AG and Alois Treindl, 1991, 1993.     |
  63. | The use of this source code is subject to regulations made  |
  64. | by Astrodienst Zurich. The code is NOT in the public domain.|
  65. |                                                             |
  66. | This copyright notice must not be changed or removed        |
  67. | by any user of this program.                                |
  68. ---------------------------------------------------------------
  69. ************************************************************/
  70.  
  71. /************************************************************
  72. $Header: ourdef.h,v 1.2 91/11/16 16:21:37 alois Exp $
  73. definitions and constants for all Astrodienst C programs
  74. contains only declarations and #defines, no global variables.
  75. auto-dectection of MSDOS (TURBO_C or MS_C) or HPUNIX
  76. ************************************************************/
  77.  
  78. #ifdef MSDOS  /* already defined by some DOS compilers */
  79. #undef MSDOS
  80. #define MSDOS 1
  81. #endif
  82.  
  83. #ifdef __TURBOC__ /* defined by turboc */
  84. #ifndef MSDOS
  85. #define MSDOS 1
  86. #endif
  87. #define TURBO_C
  88. #endif
  89.  
  90. #if MSDOS
  91. #define HPUNIX 0
  92. #ifndef TURBO_C
  93. #define MS_C /* assume Microsoft C compiler */
  94. #endif
  95. #else
  96. #define MSDOS 0
  97. #define HPUNIX 1
  98. #ifndef _HPUX_SOURCE
  99. #define _HPUX_SOURCE
  100. #endif
  101. #endif
  102.  
  103. #include <stdlib.h>
  104. #if HPUNIX
  105. #ifndef MAC
  106. #ifndef NeXT
  107. #include <unistd.h>
  108. #endif
  109. #endif /* MAC */
  110. #endif /* HPUNIX */
  111.  
  112. #ifndef OK
  113. #define OK 0
  114. #define ERR (-1)
  115. #endif
  116.  
  117.  
  118. #define UCHP (unsigned char*)  /* used for casting *char  */
  119. #define UCP (unsigned char*)  /* used for casting *char  */
  120. #define SCP (char*)     /* used for casting *unsigned char */
  121. #define UCHAR unsigned char
  122.  
  123. #if HPUNIX
  124. #ifndef MAC
  125. #ifndef NeXT
  126. #include <malloc.h>
  127. #endif
  128. #endif /* MAC */
  129. typedef double  REAL8;  /* real with at least 64 bit precision */
  130. typedef float   REAL4;  /* real with at least 32 bit precision */
  131. typedef long    INT4;   /* signed integer with at least 32 bit precision */
  132. typedef unsigned long UINT4;
  133. /* unsigned integer with at least 32 bit precision */
  134. typedef int     INT2;   /* signed integer with at least 16 bit precision */
  135. typedef int     INT1;   /* signed integer with at least 8  bit precision */
  136. #ifndef dbd_VERSION     /* db_vista defines boolean in vista.h already */
  137. typedef int     BOOLEAN;
  138. #endif
  139. typedef unsigned short UINT2; /* unsigned 16 bits */
  140. #define ABS4  abs   /* abs function for long */
  141. #endif /* HPUNIX */
  142.  
  143. #if MSDOS
  144. #ifdef TURBO_C
  145. #include <alloc.h>    /* MSC needs malloc ! */
  146. #else
  147. #include <malloc.h>
  148. #endif
  149. typedef double  REAL8;  /* real with at least 64 bit precision */
  150. typedef float   REAL4;  /* real with at least 32 bit precision */
  151. typedef long    INT4;   /* signed integer with at least 32 bit precision */
  152. typedef unsigned long UINT4;
  153.                         /* unsigned integer with at least 32 bit precision */
  154. typedef int     INT2;   /* signed integer with at least 16 bit precision */
  155. typedef int     INT1;   /* signed integer with at least 8  bit precision */
  156. typedef int     BOOLEAN;
  157. typedef unsigned int UINT2; /* unsigned 16 bits */
  158. #define ABS4  labs    /* abs function for long */
  159. #endif /* MSDOS */
  160.  
  161. #define COS8 RCos
  162. #define SIN8 RSin
  163. #define ASIN8 asin
  164. #define TAN8 RTan
  165. #define ATAN8 RAtn
  166. #define ATAN28 atan2
  167. #define EXP10(x) pow(10.0, (x))
  168. #define ABS8(x) RAbs(x)
  169.  
  170. #define TANERRLIMIT 1.0E-10     /* used to check for arguments close to pi */
  171. #define NEAR_ZERO   1.0E-16     /* used to compare for divisors close to 0 */
  172. #define BIGREAL     1.0E+38
  173.  
  174. #define DEGTORAD 0.0174532925199433
  175. #define RADTODEG 57.2957795130823
  176.  
  177. typedef INT4 centisec;   /* centiseconds used for angles and times */
  178. #define CS   (centisec)  /* use for casting */
  179. #define CSEC centisec    /* use for typing */
  180.  
  181. #define DEG     (360000L)   /* degree expressed in centiseconds */
  182. #define DEG7_30 (2700000L)  /* 7.5 degrees */
  183. #define DEG15   (15 * DEG)
  184. #define DEG24   (24 * DEG)
  185. #define DEG30   (30 * DEG)
  186. #define DEG60   (60 * DEG)
  187. #define DEG90   (90 * DEG)
  188. #define DEG120  (120 * DEG)
  189. #define DEG150  (150 * DEG)
  190. #define DEG180  (180 * DEG)
  191. #define DEG270  (270 * DEG)
  192. #define DEG360  (360 * DEG)
  193.  
  194. #define CSTORAD 4.84813681109536E-08 /* centisec to rad: pi / 180 /3600/100 */
  195. #define RADTOCS 2.06264806247096E+07 /* rad to centisec 180*3600*100/pi */
  196.  
  197. #define DEG2MSEC 3600000.0  /* degree to milliseconds */
  198. #define DEG2CSEC 360000.0   /* degree to centiseconds */
  199.  
  200. #define SEC2CSEC 100  /* seconds to centiseconds */
  201.  
  202. #define CS2DEG    (1.0/360000.0)  /* centisec to degree */
  203. #define CS2CIRCLE (CS2DEG/360.0)  /* centisec to circle */
  204. #define AU2INT    1e7             /* factor for long storage of A.U. */
  205.  
  206. #define CSMIN 6000L
  207. #define CSSEC 100L
  208.  
  209. #define SINDEG(x) sin(DEGTORAD * (x))
  210. #define COSDEG(x) cos(DEGTORAD * (x))
  211. #define TANDEG(x) tan(DEGTORAD * (x))
  212. #define SINCS(x)  sin((double)(CSTORAD * (x)))
  213. #define COSCS(x)  cos((double)(CSTORAD * (x)))
  214. #define TANCS(x)  tan((double)(CSTORAD * (x)))
  215.  
  216. /*************************************************************
  217. Exported functions:
  218.  
  219. In all functions the variable jd_ad indicates the use of
  220. Astrodienst relative julian days, and jd the use of absolute
  221. julian days.
  222. *************************************************************/
  223.  
  224. extern int nacalc();
  225. extern int calcserv();
  226. extern void helup();
  227. extern void togeo();
  228. extern int calc();
  229. extern int hel();
  230. extern int moon();
  231. extern REAL8 sidtime();
  232. extern REAL8 smod8360();
  233. extern REAL8 mod8360();
  234. extern REAL8 diff8360();
  235. extern REAL8 test_near_zero();
  236. extern REAL8 deltat();
  237. extern void to_mean_ekl();
  238. extern int afl2planet();
  239. extern void disturb();
  240. extern REAL8 fnu();
  241.  
  242. /*************************************************************
  243. definitions
  244. *************************************************************/
  245.  
  246. /*
  247. * planet index numbers, used to identify a planet in calc() and
  248. * other related functions.
  249. */
  250. #define SUN       0   /* used synonymously for earth too */
  251. #define EARTH     0
  252. #define MOON      1
  253. #define MERCURY   2
  254. #define VENUS     3
  255. #define MARS      4
  256. #define JUPITER   5
  257. #define SATURN    6
  258. #define URANUS    7
  259. #define NEPTUNE   8
  260. #define PLUTO     9
  261. #define MEAN_NODE 10
  262. #define TRUE_NODE 11
  263. #define CHIRON    12
  264. #define LILITH    13
  265. #define CERES     14
  266. #define PALLAS    15
  267. #define JUNO      16
  268. #define VESTA     17
  269.  
  270. /*************************************************************
  271. exported variables
  272. *************************************************************/
  273.  
  274. extern REAL8 meanekl;
  275. extern REAL8 ekl;
  276. extern REAL8 nut;
  277.  
  278. extern struct elements { /* actual elements at time thelup */
  279.   REAL8 tj,     /* centuries from epoch */
  280.   lg,     /* mean longitude in degrees of arc*/
  281.   pe,     /* longitude of the perihelion in degrees of arc*/
  282.   ex,     /* excentricity in degrees of arc*/
  283.   kn,     /* longitude of node in degrees of arc*/
  284.   in,     /* inclination of the orbit in degrees of arc*/
  285.   ma;     /* mean anomaly in degrees of arc*/
  286. } el [MARS + 1];
  287.  
  288. extern char *ephe_path;
  289.  
  290. /*
  291. * in a bitlist flag each planet is represented by a bit;
  292. * all 13 defined planets can be called at once with
  293. * LILITH is not automatically included
  294. */
  295. #define CALC_ALL_PLANET_BITS ((1 << 13) - 1) /* bits 0..12 set */
  296.  
  297. #define J2000 2451545.0 /* Epoch of JPL ephemeris DE200, absolute */
  298. #define J1950  2433282.423  /* Epoch of JPL ephemeris DE102 */
  299. #define JUL_OFFSET 2433282.0  /* offset of Astrodienst relative Julian date */
  300. #define EPOCH1850 -36524.0  /* jupiter,saturn 0 jan 1850, 12:00 */
  301. #define EPOCH1900 -18262.0  /* inner planets  0 jan 1900, 12:00 */
  302. #define EPOCH1950  0.0    /* pluto    0 jan 1950, 12:00 */
  303.                 /* this is the origin of the Astrodienst
  304.                    relative julian calendar system */
  305. #define EPOCH1960 3653.0 /* uranus,neptune 1 jan 1960, 12:00 */
  306.  
  307. #define ENDMARK 99 /* used to mark the end of disturbation terms */
  308.  
  309. #define NODE_INTERVAL 0.005        /* days, = 7m20s */
  310. #define MOON_SPEED_INTERVAL 0.0001 /* 8.64 seconds later */
  311.  
  312. /*
  313. * flag bits used in calc and calcserv
  314. */
  315. #define CALC_BIT_HELIO 1   /* geo/helio */
  316. #define CALC_BIT_NOAPP 2   /* apparent/true positions */
  317. #define CALC_BIT_NONUT 4   /* true eq. of date/ mean equ. of date */
  318. #define CALC_BIT_EPHE  8   /* universal/ephemeris time */
  319. #define CALC_BIT_SPEED 16  /* without/with speed */
  320. #define CALC_BIT_BETA  32  /* without/with latitude */
  321. #define CALC_BIT_RGEO  64  /* without/with relative rgeo */
  322. #define CALC_BIT_RAU   128 /* without/with real radius */
  323. #define CALC_BIT_MUST_USE_EPHE 256 /* epheserv may not use calc */
  324. #define CALC_BIT_MAY_USE_EPHE  512 /* calcserv may use ephread */
  325.  
  326. #define EPHE_STEP 80              /* days step in LRZ ephe */
  327. #define EPHE_DAYS_PER_FILE 100000 /* days per ephe file */
  328. #define EPHE_OUTER "LRZ5_"        /* file name prefix */
  329. #define EPHE_OUTER_BSIZE  60      /* blocksize */
  330. #define EPHE_CHIRON "CHI_"        /* file name prefix */
  331. #define EPHE_CHIRON_BSIZE 12      /* blocksize */
  332. #define EPHE_ASTER "CPJV_"        /* file name prefix */
  333. #define EPHE_ASTER_BSIZE  48      /* blocksize */
  334.  
  335. /********************************************
  336. About the format of the ephemeris files
  337. ----------------------------------------
  338. We use currently ephemeris files with steps of 80 days.
  339. There are 1250 "records" in each file, so that one file
  340. spans 100000 days. We have three types of ephemeris files:
  341. LRZ5_nn for the outer planets Jupiter ... Pluto,
  342. CHI_nn for Chiron, and CPJV_nn for the four asteroids Ceres ... Vesta.
  343. nn is an expression derived from the first julian daynumber on the
  344. file. Jd 2100'000 to 2199'920 is on file LRZ5_21, CHI_21, and CPJV_21;
  345. for negative Jd we use the filenames LRZ5_Mxx  with M indicating the minus.
  346.  
  347. Given the jd for which you want the ephemeris, it is simple to build
  348. the filename and use fseek() within the file to go where the data is.
  349. This is done by the functions lrz_file_posit() and chi_file_posit().
  350.  
  351. The stored coordinates are for each date and planet:
  352. L = ecliptic longitude relative to mean exquinox of date,
  353. in units of milliseconds of acr (1/3600000 degree) as type long;
  354. R = radius vector, units of 10-7 AU, as type long.
  355. Z = disctance of ecliptic; Z = R * sin(latitude); in units of 10-7 AU,
  356. as type long.
  357. The data is stored in the byte ordering of the Astrodienst HPUX machines,
  358. which is most significant byte first. It is not the same byte ordering
  359. as on Intel processors; the function longreorder() converts between
  360. the disk file format and the internal format of MSDOS machines.
  361.  
  362. For LRZ5- files, we have 60-byte records LRZ(Jupiter),LRZ(Saturn),
  363. LRZ(Uranus), LRZ(Neptune), LRZ(Pluto).
  364. For CHI- files we have 12-byte records LRZ.
  365. For CPJV- files we have 48-byte records.
  366.  
  367. ************************************************/
  368.  
  369.  
  370. /*************************************************************
  371. placalc2.c definitions
  372. *************************************************************/
  373.  
  374. #define SDNUM 20
  375. #define NUM_MOON_CORR 93
  376.  
  377. struct eledata {
  378. REAL8 axis,   /* mean distance, in a.u., A(N) in basic */
  379. period,   /* days for one revolution, P(N) in basic */
  380. epoch,    /* relative juldate of epoch, Ep(N) in basic */
  381. /* T = distance to epoch in jul.centuries 36525 day*/
  382. lg0,lg1,lg2,lg3,/* deg(epoch), degree/day, seconds/T^2,seconds/T^3 */
  383. /* Pd(N,0..2) in basic, lg3 was not present */
  384. pe0,pe1,pe2,pe3,/* deg(epoch), seconds/T,  seconds/T^2,seconds/T^3 */
  385. /* Pd(N,3..5) in basic, pe3 was not present */
  386. ex0,ex1,ex2,  /* ecl(epoch), 1/T, 1/T^2 */
  387. /* Pd(N,6..8) in basic */
  388. kn0,kn1,kn2,kn3,/* node(epoch),seconds/T,  seconds/T^2,seconds/T^3 */
  389. /* Pd(N,9..11) in basic, kn3 was not present */
  390. in0,in1,in2;    /* incl(epoch),1/T, 1/T^2 */
  391. /* Pd(N,12..14) in basic */
  392. };
  393.  
  394. struct kor {
  395.   int     j, i;
  396.   REAL8   lampl;  /* amplitude of disturbation in long, seconds of arc */
  397.   REAL8 lphase;   /* phase of disturbation in long, degrees */
  398.   INT4    rampl;  /* ampl. of disturbation in radius, 9th place of log */
  399.   REAL8   rphase; /* phase of disturbation in radius, degrees */
  400.   int     k;      /* index into disturbing planet anomaly table sa[] */
  401. };
  402.  
  403. struct sdat {   /* 0..19 mean anomalies of disturbing planets
  404.   Sd(0..19,0..1) in basic */
  405.   REAL8 sd0,  /* mean anomaly at epoch 1850 */
  406.   sd1;  /* degrees/year */
  407. };
  408.  
  409. /* moon correction data; revised 30-jul-88: all long. to 0.3" */
  410. struct m45dat {
  411.   int  i0,i1,i2,i3;
  412.   REAL8 lng,lat,par;
  413. };
  414.  
  415. extern struct eledata pd[MARS + 1];
  416. extern struct kor earthkor[86+1];
  417. extern struct kor mercurykor[24+1];
  418. extern struct kor venuskor[22+1];
  419. extern struct kor marskor[62+1];
  420. extern struct sdat _sd [SDNUM];
  421. extern struct m45dat m45[NUM_MOON_CORR];
  422. extern REAL8 ekld[4];
  423. extern REAL8 sa[SDNUM];
  424. extern double degnorm();
  425. extern REAL8 fnu();
  426. extern REAL8 smod8360();
  427. extern REAL8 mod8360();
  428. extern REAL8 diff8360();
  429. extern REAL8 test_near_zero();
  430.  
  431. /*******************************************
  432. $Header: astrolib.h,v 1.2 91/11/16 16:21:02 alois Exp $
  433. astrolib.h
  434.  
  435. *******************************************/
  436.  
  437. /* macros for bit operations */
  438.  
  439. #define clear_bit(v,bit_nr) ((v) & ~(1L << (bit_nr)))
  440. #define set_bit(v,bit_nr)   ((v) | (1L << (bit_nr)))
  441. #define bit(bit_nr)         (1L << (bit_nr))
  442. #define check_bit(v,bit_nr) ((v) & (1L << (bit_nr)))
  443.  
  444. #endif /* PLACALC */
  445.  
  446. /* placalc.h */
  447.